<?php

namespace App\ModelFilters;

use EloquentFilter\ModelFilter;

class Qh_OrderFilter extends ModelFilter
{
    /**
     * Related Models that have ModelFilters as well as the method on the ModelFilter
     * As [relationMethod => [input_key1, input_key2]].
     *
     * @var array
     */
    public $relations = [];

    public function status($v)
    {
        if (!is_null($v) && $v != "null") {
            if (!is_array($v)) $v = array_filter(explode(',', $v));
            return $this->whereIn('tiku_order.status', $v);
        }
    }

    public function nickname($v) {
        return $this->whereHas('user', function ($q) use ($v) {
            $q->where('nickname', 'like', '%'.$v.'%');
        });
    }

    public function mobile($v) {
        return $this->whereHas('user', function ($q) use ($v) {
            $q->where('mobile', $v);
        });
    }

    public function no($v) {
        return $this->where('tradeNo', $v)->orWhere('wxTradeNo', $v);
    }

    public function id($value) {
        return $this->where('tiku_order.id', $value);
    }

    public function ids($value) {
        return $this->whereIn('tiku_order.id', explode(',', $value));
    }

    public function userId($value) {
        return $this->where('userId', $value);
    }
}
